using UnityEngine;
using System.Collections;

public class UtilsMath {
	
	public static Vector2 rotatePoint(Vector2 point, float angle, Vector2 origin){
		point -= origin;
		
		float px = point.x;
		float py = point.y;
		point.x = px*Mathf.Cos(angle) - py*Mathf.Sin(angle);
		point.y = px*Mathf.Sin(angle) + py*Mathf.Cos(angle);
		
		return point+origin;
	}
	public static Rect rotateRect(Rect rect, float angle, Vector2 origin){
		Vector2 p1 = rotatePoint(new Vector2(rect.xMin,rect.yMin),angle,origin);
		Vector2 p2 = rotatePoint(new Vector2(rect.xMax,rect.yMax),angle,origin);
		
		Vector2 r1 = p1;
		Vector2 r2 = p2;
		if(p2.x<p1.x){
			r1.x = p2.x;
			r2.x = p1.x;
		}
		if(p2.y<p1.y){
			r1.y = p2.y;
			r2.y = p1.y;
		}
		return Rect.MinMaxRect(r1.x,r1.y,r2.x,r2.y);
	}
}

